<template>
	<div class="myOreder">


		<div class='clearfloat'>
			<orderStatistics class='fl' :myInfo ='myInfo' :roleID='roleID'  @getData='getData'/>
			<!-- <el-button v-no-more-click:3000 class="mb10 fl mr10" >+添加订单</el-button> -->
			<el-button type="success" icon="el-icon-plus" circle @click="addOrder" v-if="$store.state.user.is_teacher != 2"></el-button>
			<el-popover placement="left" trigger="click">
				<template>
					<el-checkbox v-model="tableHeader.checked" @change="selectAll">全选</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked0">耗时</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked1">订单编号</el-checkbox>
					<br />
					<el-checkbox v-if="roleID!=2" v-model="tableHeader.checked2">代理人</el-checkbox>
					<br v-if="roleID!=2" />
					<el-checkbox v-model="tableHeader.checked6">流程状态</el-checkbox>
					<br />
					<el-checkbox v-if="$store.state.user.is_teacher == 2" v-model="tableHeader.checked18">导师审核状态</el-checkbox>
					<br v-if="$store.state.user.is_teacher == 2"/>
					<el-checkbox v-model="tableHeader.checked16">专利类型</el-checkbox>
					<br />
					<!-- <el-checkbox v-model="tableHeader.checked19">缴费状态</el-checkbox>
					<br /> -->
					<el-checkbox v-model="tableHeader.checked17">流程人员</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked21">代理人</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked3">拟申报专利名称</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked20">附图</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked4">联络人</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked5">电话</el-checkbox>
					<br />
					<el-checkbox v-if="roleID!=2" v-model="tableHeader.checked7">专利权人</el-checkbox>
					<br v-if="roleID!=2" />
					<el-checkbox v-model="tableHeader.checked8">发明人</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked9">审核次数</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked10">邮箱</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked11">内容审核文件</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked12">完成文件上传</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked13">提交时间</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked14">修改时间</el-checkbox>
					<br />
					<el-checkbox v-model="tableHeader.checked15">接单时间</el-checkbox>
					<br />
				</template>
				<el-button style="float: right;margin-bottom: 5px;margin-top: 0;" slot="reference" icon="el-icon-arrow-down">显示字段</el-button>
			</el-popover>

			<!-- 列表查找 -->
			<span class="down-execel">
				<Poptip v-model="showFilter" placement="bottom-end" @on-popper-show ='getAllAgent'>
					<i class="el-icon-search poptip-condition-add"></i>
					<a href="javascript:;" class='poptip-condition-add'>列表查找</a>
					<div slot="content">
						<Poptip v-model="showFilterCondition" placement="bottom-start" class='poptip-condition'>
							<i class="el-icon-plus"></i>
							<a href="javascript:;">添加过滤条件</a>

							<div slot="content" class="condition-list">
								<ul>
									<li v-for="(item, index) in getTeacherColumns" class='poptip-condition-item' @click="addFilterCondition(item)" :key="index">{{item.label}}</li>
								</ul>
							</div>
						</Poptip>

						<el-form :model="conditionForm" ref="conditionForm" label-min-width="120px" class="demo-dynamic" @submit.native.prevent>
							<el-form-item v-for="(condition, index) in conditionForm.condition" :label="condition.label" :key="condition.key"
								:prop="'condition.' + index + '.value'" :rules="{
										required: true, message: condition.label + '不能为空', trigger: 'blur'
									}">
								<el-select
									size="small"
									filterable
									v-model="condition.value"
									v-if='condition.label === "流程人员"'>
									<el-option
										v-for="item in processOptions"
										:key="item.id"
										:label="roleID == 2 ? item.email_work.split('@')[0].split('followup')[1] : item.name"
										:value="item.id">
									</el-option>
								</el-select>
								<el-select
									size="small"
									filterable
									v-model="condition.value"
									v-else-if='condition.label === "代理人"'>
									<el-option
										v-for="item in agentOptions"
										:key="item.id"
										:label="item | agentNumAddName"
										:value="item.id">
									</el-option>
								</el-select>

								<el-select v-else-if='condition.label === "流程状态"' v-model="condition.value" placeholder="流程状态" size="small">
									<!-- <el-option label="未接单" value="未接单"></el-option> -->
									<el-option label="代理人撰写中" value="代理人撰写中"></el-option>
									<el-option label="案件内审中" value="案件内审中"></el-option>
									<el-option label="案件修改中" value="案件修改中"></el-option>
									<el-option label="定稿文件发送中" value="定稿文件发送中"></el-option>
									<el-option label="发明人确认定稿中" value="发明人确认定稿中"></el-option>
									<el-option label="上报文件上传中" value="上报文件上传中"></el-option>
									<el-option label="文件格式审核中" value="文件格式审核中"></el-option>
									<!-- <el-option label="已撤案" value="已撤案"></el-option> -->
								</el-select>

								<el-select v-else-if='condition.label === "专利类型"' v-model="condition.value" placeholder="请选择专利类型" size="small">
									<el-option label="发明专利" value="发明专利"></el-option>
									<el-option label="实用新型" value="实用新型"></el-option>
									<el-option label="外观设计" value="外观设计"></el-option>
									<el-option label="不确定" value="不确定"></el-option>
								</el-select>
								<el-select v-else-if='condition.label === "缴费状态"' v-model="condition.value" placeholder="请选择缴费状态" size="small">
									<el-option label="未缴费" value="1"></el-option>
									<el-option label="已缴费" value="2"></el-option>
								</el-select>

								<el-date-picker
									v-model="submitTime"
									:validate-event='false'
									@input = 'changInput'
									type="daterange" placeholder="选择日期" value-format="yyyy-MM-dd" size="small"
								 	v-else-if='condition.label === "提交时间"'>
								</el-date-picker>

								<el-input v-else size="small" v-model="condition.value" @keyup.enter.native="submitsearch('conditionForm')"></el-input>
								<el-button @click.stop="removeDomain(condition)" size="mini">删除</el-button>
							</el-form-item>
						</el-form>

						<div class="btns">
							<el-button @click="submitsearch('conditionForm')" size="mini">查询</el-button>
							<el-button @click="resetForm('conditionForm')" size="mini">重置</el-button>
						</div>
					</div>
				</Poptip>
			</span>
		</div>


		<el-table
			v-if="table_show"
			:data="tableData"
			border
			style="width: 100%"
			v-loading="loading"
			:row-class-name="tableRowClassName"
			ref="orderTb"
			@row-click="lookOrder"
			height="88%"
			@sort-change='tableSortChange'>
			<el-table-column show-overflow-tooltip key="1" prop="id" label="ID" min-width="60" align="left" v-if='checked99'>
				<template slot-scope="scope">{{(scope.$index+1)+(currentPage-1)*tableSize}}</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip  key="2" v-if="tableHeader.checked0" label="耗时(天)" min-width="130" align="left"  prop="pick_up_date" sortable='custom'>
				<template slot-scope="scope">
					<template v-if ='scope.row.pick_up_date'>
						<span v-if="getProcessingTime(scope.row.pick_up_date) > 25" class="font_danger">
							{{ getProcessingTime(scope.row.pick_up_date) }}
						</span>
						<span v-else>
							{{ getProcessingTime(scope.row.pick_up_date) }}
						</span>
					</template>
				  <template v-else>
						<span v-if="getProcessingTime(scope.row.created_at) > 25" class="font_danger">
							{{ getProcessingTime(scope.row.created_at) }}
						</span>
						<span v-else>
							{{ getProcessingTime(scope.row.created_at) }}
						</span>
					</template>


				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip v-if="tableHeader.checked1"  sortable='custom' key="4" prop="order_number" label="订单编号" min-width="200" align="left"></el-table-column>
			<el-table-column show-overflow-tooltip key="5"  sortable='custom' v-if="tableHeader.checked6" prop="status" label="流程状态" min-width="120" align="left">
				<template slot-scope="scope">
					<span :class="scope.row.status == '案件修改中' ? 'font_warning' : ''">
						{{ scope.row.status }}
					</span>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip sortable='custom' v-if="tableHeader.checked18checked18 && $store.state.user.is_teacher == 2" prop="status" label="导师审核状态" min-width="130" align="left">
				<template slot-scope="scope">
					<span>{{ scope.row | teacherAuditorStatus }}</span>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="18"  sortable='custom' v-if="tableHeader.checked16" prop="type" label="专利类型" min-width="120" align="left"></el-table-column>
			<el-table-column show-overflow-tooltip key="6" v-if="tableHeader.checked3" prop="patent_name" label="拟申报专利名称" min-width="200"  sortable='custom' align="left"></el-table-column>
			<el-table-column
				label="附图"
				key="20"
				v-if="tableHeader.checked20"
				min-width="150"
				sortable="custom"
				align="left">
				<template slot-scope="scope">
					<div v-if="scope.row.imgArr" class="img-wrap" @click.stop>
						<pre-img
							:smallImg="scope.row.imgArr"
							:bigImg="scope.row.imgArr2"
							class="pre-img">
						</pre-img>
						<!-- <div v-for="(item, index) in scope.row.imgArr" :key="index">
							<el-image
								v-if="index < 3"
								:key="index"
								:src="item"
								:preview-src-list="scope.row.imgArr"
							></el-image>
						</div> -->
					</div>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="7" v-if="tableHeader.checked4" prop="liaisons" label="联络人" min-width="100" align="left"  sortable='custom'>
				<template slot-scope="scope">
					<span>{{scope.row.liaisons}}</span>
					<Tooltip  v-if="roleID == 2 && $store.state.is_teacher == 1"  content="点我留言">
						<i class="el-icon-chat-dot-round leaveWord"  @click.stop="leaveWord(scope.row, '1')"></i>
					</Tooltip>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip  v-if="tableHeader.checked8" prop="user_name" label="发明人" min-width="100" align="left"  sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip key="8" v-if="tableHeader.checked5" prop="liaisons_tel" label="电话" min-width="120" align="left"  sortable='custom'></el-table-column>
			<el-table-column show-overflow-tooltip key="12" v-if="tableHeader.checked10" prop="liaisons_email" label="邮箱"  min-width="180"  sortable='custom' align="left"></el-table-column>
			<el-table-column show-overflow-tooltip key="19"  v-if="tableHeader.checked17" prop="process" label="流程人员" min-width="120" align="left" sortable>
				<template slot-scope="scope">
					<span>{{ scope.row.process | processNumber }}</span>
					<Tooltip  v-if="roleID == 2 && $store.state.is_teacher == 1"  content="点我留言">
						<i class="el-icon-chat-dot-round leaveWord"  @click.stop="leaveWord(scope.row, '2')"></i>
					</Tooltip>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="3" v-if="tableHeader.checked21 && $store.state.user.is_teacher ==1" prop="agent" label="代理人" min-width="140" align="left" sortable='custom'>
				<template slot-scope="scope">
					{{ scope.row.agent | agentNumAddName }}
				</template>
			</el-table-column>
			<!-- <el-table-column show-overflow-tooltip key="21"  v-if="tableHeader.checked19" prop="is_payed" label="缴费状态" min-width="120" align="left" sortable>
				<template slot-scope="scope">

					<span v-if='scope.row.is_distribution == 3' :class="scope.row.order_pay ? 'font_success' : 'font_danger'">{{ scope.row.order_pay | orderPay }}</span>
					<span v-else>-</span>
				</template>
			</el-table-column> -->
			<el-table-column show-overflow-tooltip key="11"  v-if="tableHeader.checked9" prop="opinions_count" label="审核次数" min-width="120" align="left"  sortable='custom'></el-table-column>
			<el-table-column key="13" v-if="tableHeader.checked11" prop="review_file" label="内容审核文件" min-width="200" align="left">
				<template slot-scope="scope">
					<div class='flie-hid'>
						<a v-for="item in scope.row.reviewfileArr" :key="item.id" :href="baseUrl + '/api/download?path=' + item.file +'/'+ item.path"
							:download="item.path" :title="item.path" class="el-icon-tickets file_sh" @click.stop="stopLook"></a>
					</div>
				</template>
			</el-table-column>
			<el-table-column show-overflow-tooltip key="15" v-if="tableHeader.checked13" label="提交时间" prop="created_at" min-width="160" sortable align="left">
				<!-- <template slot-scope="scope">{{ getOrderCreateTime(scope.row) }}</template> -->
			</el-table-column>
			<el-table-column show-overflow-tooltip key="16" v-if="tableHeader.checked14" label="修改时间" min-width="160" prop="updated_at" sortable align="left">
				<!-- <template slot-scope="scope">{{ getUpdateTime(scope.row) }}</template> -->
			</el-table-column>
			<el-table-column show-overflow-tooltip key="17" v-if="tableHeader.checked15 && roleID == 2" label="接单时间" min-width="160" sortable prop="pick_up_date" align="left">
				<!-- <template slot-scope="scope">{{ getOrderTakingTime(scope.row) }}</template> -->
			</el-table-column>

			<!-- 代理人 -->
			<el-table-column show-overflow-tooltip :fixed="isFixed" width="100" v-if="roleID == 2 && checked99" align="center">
				<template slot="header">
					<span class="tableLastCol">操作</span>
				</template>
				<template slot-scope="scope">
					<el-button type="primary" size="small" @click.stop="lookOrder(scope.row)">处理订单</el-button>
				</template>
			</el-table-column>
		</el-table>

		<el-pagination class="pagination" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
		  :page-sizes="pageSizes" :page-size="Number(pageSize)" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>

		<!-- 查看 -->
		<lookDialog @refresh="search" :order_process="order_process" :order_agent="order_agent" ref="orderDialog" @chageData="search" ></lookDialog>

		<!-- 进度 -->
		<processScheduleDialog ref="scheduleDialog"></processScheduleDialog>

		<!-- 定稿文件 -->
		<finalizationDialog :order_id="order_id" ref="finalizationFile" @chageData="search"></finalizationDialog>

		<xy-excel-export-template ref="TerminalExportExcel"></xy-excel-export-template>

		<!-- 新增订单 -->
		<agentOrderOperate ref="agentOrderOperate" @refresh="search"></agentOrderOperate>
	</div>
</template>

<script>
	import lookDialog from "./dialogPage/dialogOrder"; //查看弹出层
	import processScheduleDialog from "./dialogPage/processSchedule"; //进度弹出层
	import finalizationDialog from "./dialogPage/uploadFile"; //定稿文件弹出层
	import agentOrderOperate from '../agentOrder/components/agentOrder-operate'
	import countDown from "~/components/countDown";

	// 方法的JS文件
	import orderFn from "./getOrderList";
	import xyExcelExportTemplate from "~/components/ExcelExportTemplate";
	import orderStatistics from "~/components/orderStatistics"
	import preImg from '~/components/pre-img'
	import { agentLeaveWord } from "~/util/index"
	export default {
		head: {
			title: "处理中订单"
		},
		name: "inProcessing",
		components: {
			lookDialog, //查看弹出层
			processScheduleDialog, //进度弹出层
			finalizationDialog, //定稿文件上传弹出层
			countDown,
			xyExcelExportTemplate,
			orderStatistics,
			preImg,
			agentOrderOperate
		},
		data() {
			return {
				order_id: '',
				loading: true,
				isFixed: "right",
				tableData: [],
				//默认域名
				baseUrl: global.baseurl,
				//角色
				roleID: 1,
				// 分页
				tableSize: 10, //一页几条
				currentPage: 1, //目前在第几页
				pageSizes: [25, 50], //一页可以几条
				strTime: "",
				myInfo: {
					agentOrderCount: 0,
					unPaymentCount: 0
				},
				table_show: true,
				checked99: true,
				tableHeader: {
					checked: true,
					checked0: true,
					checked1: true,
					checked2: true,
					checked3: true,
					checked4: true,
					checked5: true,
					checked6: true,
					checked16: true,
					checked17: true,
					checked7: true,
					checked8: true,
					checked9: true,
					checked10: true,
					checked11: true,
					checked12: true,
					checked13: true,
					checked14: true,
					checked15: true,
					checked18: true,
					checked19: true,
					checked20: true,
					checked21: true,
				},
				total: 0,
				order_process: {},
				order_agent: {},
				showFilter: false, // 控制显示筛选条件
				showFilterCondition: false,
				conditionForm: {
					condition: []
				}, //筛选条件
				columns: [
					{
						label: '订单编号',
						id: 2,
						parameter: 'order_number'
					},
					{
						label: '流程状态',
						id: 3,
						parameter: 'status'
					},
					{
						label: '专利类型',
						id: 4,
						parameter: 'type'
					},
					{
						label: '流程人员',
						id: 5,
						parameter: 'process_id'
					},

					{
						label: '拟申报专利名称',
						id: 6,
						parameter: 'patent_name'
					},
					{
						label: '联络人',
						id: 7,
						parameter: 'liaisons'
					},
					{
						label: '缴费状态',
						id: 16,
						parameter: 'is_payed'
					},
					{
						label: '电话',
						id: 8,
						parameter: 'liaisons_tel'
					},
					{
						label: '发明人',
						id: 9,
						parameter: 'user_name'
					},
					{
						label: '专利权人',
						id: 10,
						parameter: 'patent_user'
					},
					{
						label: '邮箱',
						id: 12,
						parameter: 'liaisons_email'
					},
					{
						label: '提交时间',
						id: 15,
						parameter: 'subimt_time'
					}
				],
				lastTime: 0,
				searchValue: '',
				submitTime: [],
				restaurants2: [],
				processOptions: [],
				paramsByOrder: {
					status: "代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中",
					sort_str: 'pick_up_date',
					sort_order: 'asc',
				},
				agentOptions: [],
			};
		},
		async asyncData({
			$axios,
			store,
			route
		}) {
			const STATUS = "代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中"
			let paramsByOrder = {
				status: STATUS,
				sort_str: 'pick_up_date',
				sort_order: 'asc',

			};

			if (store.state.fromStatistics == 'isFromStatistics') {
				paramsByOrder.status = '案件修改中'
			} else {
				paramsByOrder.status = STATUS
			}

			if (store.state.user.is_teacher == 2) {
				paramsByOrder.student_order = true
				paramsByOrder.agent_id = store.state.user.id
			} else if(store.state.user.is_teacher == 1) {
				if (!paramsByOrder.agent_id) {
					paramsByOrder.all_student_order = true
				} else {
					delete paramsByOrder.all_student_order
				}
			} else {
				paramsByOrder.agent_id = store.state.user.id
			}
			return orderFn.getOrderByasync($axios, store, paramsByOrder); //,true
		},
		computed: {
			getTeacherColumns () {
				let columnsData = this.columns
				let item = {
					label: '代理人',
					id: 21,
					parameter: 'agent_id'
				}
				if (this.$store.state.user.is_teacher == 1) {
					if (columnsData.findIndex(v => v.label == '代理人')) {
						let index = columnsData.findIndex(v => v.label == '代理人')
						columnsData.splice(index, 1);
					}
					columnsData.splice(3, 0, item);
				}
				return columnsData
			}
		},
		created() {
			// console.log(this.$store.state)
		},
		methods: {
			leaveWord (data, type) {
				agentLeaveWord(data, type, this)
			},
			addOrder () {
				this.$refs['agentOrderOperate'].show()
			},
			selectAll(val) {
				for( let i in this.tableHeader) {
					this.tableHeader[i] = val
				}
			},
			async tableDataRefresh() {
				// if (this.$store.state.user.role_id == 2 && this.paramsByOrder.agent_id) {
				// 	this.paramsByOrder.agent_id = this.$store.state.user.id;
				// }
				if (this.$store.state.user.is_teacher == 2) {
					this.paramsByOrder.student_order = true
					this.paramsByOrder.agent_id = this.$store.state.user.id
				} else if(this.$store.state.user.is_teacher == 1) { 
					if (!this.paramsByOrder.agent_id) {
						this.paramsByOrder.all_student_order = true
					} else {
						delete this.paramsByOrder.all_student_order
					}
				} else {
					this.paramsByOrder.agent_id = this.$store.state.user.id
				}
				let data = await orderFn.getOrderByasync(this.$axios, this.$store, this.paramsByOrder); //,true
				for (let key in data) {
					this[key] = data[key];
				}
			},
			//修改案件标红
			tableRowClassName({
				row,
				rowIndex
				}) {
				let cssClass = "";
				if (this.$store.state.user.role_id == 2 && row.status == "案件修改中") {
					cssClass = "warning-row";
				}
				return cssClass;
			},

			//更新时间，做过倒序，直接拿第一条
			getUpdateTime(val) {
				let statusArr = val.statuss;
				let createDay = ''
				if(statusArr[0]) {
					createDay = statusArr[0].pivot.created_at;
				}

				return createDay;
			},
			//订单创建时间
			getOrderCreateTime(val) {
				let statusArr = val.statuss;
				let createDay = "";
				for (const i in statusArr) {
					if (statusArr[i].id == 1) {
						createDay = statusArr[i].pivot.created_at;
					}
				}
				return createDay;
			},
			// 处理时长
			getProcessingTime(value) {
				//获取接单的时间戳
				// createDay = createDay.replace(/-/g, "/");
				let createTime = new Date(value).getTime();
				//获取当前的时间戳
				var nowTime = new Date().getTime();
				//获取处理时间戳
				let cha = nowTime - createTime;

				function IsNaN(value) {
					return typeof value === 'number' && isNaN(value);
				}
				if (IsNaN(cha)) {
					return ''
				}

				//转换天数
				let round2 = (cha / 1000 / 60 / 60 / 24).toFixed(2)
			 	let	processingTime = (Math.ceil(round2 * 10) / 10).toFixed(1)
				if (processingTime < 0) {
					return '0.0'
				}  else if (processingTime < 0.1) {
					return '0.1'
				} else {
					return processingTime;
				}
			},

			//选择一页几条
			async handleSizeChange(size) {
				this.paramsByOrder.perPage = size
				this.paramsByOrder.page = 1

				// if (this.$store.state.user.role_id == 2 && this.paramsByOrder.agent_id) {
				// 	this.paramsByOrder.agent_id = this.$store.state.user.id;
				// }

				if (this.$store.state.user.is_teacher == 2) {
					this.paramsByOrder.student_order = true
					this.paramsByOrder.agent_id = this.$store.state.user.id
				} else if(this.$store.state.user.is_teacher == 1) { 
					if (!this.paramsByOrder.agent_id) {
						this.paramsByOrder.all_student_order = true
					} else {
						delete this.paramsByOrder.all_student_order
					}
				} else {
					this.paramsByOrder.agent_id = this.$store.state.user.id
				}

				let data = await orderFn.getOrderByasync(this.$axios, this.$store, this.paramsByOrder); //,true
				for (let key in data) {
					this[key] = data[key];
				}
			},
			//选择第几页
			async handleCurrentChange(val) {
				this.currentPage = val;
				// let parames = this.paramsByOrder
				this.paramsByOrder.page = val

				// if (this.$store.state.user.role_id == 2 && this.paramsByOrder.agent_id) {
				// 	this.paramsByOrder.agent_id = this.$store.state.user.id;
				// }
				if (this.$store.state.user.is_teacher == 2) {
					this.paramsByOrder.student_order = true
					this.paramsByOrder.agent_id = this.$store.state.user.id
				} else if(this.$store.state.user.is_teacher == 1) { 
					if (!this.paramsByOrder.agent_id) {
						this.paramsByOrder.all_student_order = true
					} else {
						delete this.paramsByOrder.all_student_order
					}
				} else {
					this.paramsByOrder.agent_id = this.$store.state.user.id
				}
				let data = await orderFn.getOrderByasync(this.$axios, this.$store, this.paramsByOrder); //,true
				for (let key in data) {
					this[key] = data[key];
				}
			},
			//查看
			lookOrder(row) {
				if (window.getSelection().toString() === '') {
					this.order_process = row.process;
					this.order_agent = row.agent || {};
					if (
						this.$store.state.user.role_id == 2 &&
						(row.status == "上报文件上传中" || row.status == "定稿文件发送中" || row.status == "发明人确认定稿中")
					) {
						this.order_id = row.order_number
						// 只有导师能上传定稿文件和上报文件
						if (this.$store.state.user.is_teacher != 2) {
							this.$refs.finalizationFile.showDialog(row);
						} else {
							// this.$alert('案件', '提示', {
							// 	confirmButtonText: '确定',
							// 	center: true,
							// 	callback: action => {
							// 		this.$message({
							// 			type: 'info',
							// 			message: `action: ${ action }`
							// 		});
							// 	}
							// });
							this.$refs.orderDialog.showDialog(row.id, "处理中");
						}
					} else {
						this.$refs.orderDialog.showDialog(row.id, "处理中");
					}
				}
			},

			//流程
			editOrder(val) {
				this.$refs.scheduleDialog.showDialog(val);
			},

			//获取表格数据
			async getData(pStatus) {
				this.roleID = this.$store.state.user.role_id;
				if (pStatus == '案件修改中') {
					this.paramsByOrder.status = '案件修改中',
					this.paramsByOrder.page = 1
					delete this.paramsByOrder.is_time_out
					delete this.paramsByOrder.is_distribution
					delete this.paramsByOrder.is_payed
				}
				if (pStatus == 'is_time_out') {
					this.paramsByOrder.status = "代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中"
					this.paramsByOrder.is_time_out = 1
					delete this.paramsByOrder.is_distribution
					delete this.paramsByOrder.is_payed
					delete this.paramsByOrder.agent_id
				}
				if (pStatus == '自提案件') {
					this.paramsByOrder.is_distribution = 3
					this.paramsByOrder.status = '案件内审中,案件修改中,上报文件上传中,文件格式审核中'
					delete this.paramsByOrder.is_time_out
					delete this.paramsByOrder.is_payed
				}
				if (pStatus == '待缴费案件') {
					this.paramsByOrder.is_distribution = 3
					this.paramsByOrder.status = '案件内审中,案件修改中,上报文件上传中,文件格式审核中,等待提交国知局'
					this.paramsByOrder.is_payed = 1
					delete this.paramsByOrder.is_time_out
				}

				// if (this.$store.state.user.role_id == 2 && this.paramsByOrder.agent_id) {
				// 	this.paramsByOrder.agent_id = this.$store.state.user.id;
				// }
				if (this.$store.state.user.is_teacher == 2) {
					this.paramsByOrder.student_order = true
					this.paramsByOrder.agent_id = this.$store.state.user.id
				} else if(this.$store.state.user.is_teacher == 1) { 
					if (!this.paramsByOrder.agent_id) {
						if (pStatus == '待缴费案件' || pStatus == '自提案件' ) {
							this.paramsByOrder.agent_id = this.$store.state.user.id
						} else {
							this.paramsByOrder.all_student_order = true
						}
					} else {
						delete this.paramsByOrder.all_student_order
					}
				} else {
					this.paramsByOrder.agent_id = this.$store.state.user.id
				}
				let data = await orderFn.getOrderByasync(this.$axios, this.$store, this.paramsByOrder); //,true
				for (let key in data) {
					this[key] = data[key];
				}
			},
			callback() {},

			//导出excel
			exportExcel(name) {
				let tabHandle = [
					"耗时",
					"代理人",
					"流程状态",
					"订单编号",
					"拟申报专利名称",
					"联络人",
					"电话",
					"专利权人",
					"发明人",
					"审核次数",
					"邮箱",
					"提交时间",
					"修改时间",
					//"审核意见"
				];
				let tabData = this.tableData;
				this.$refs.TerminalExportExcel.exportExcel(name, tabHandle, tabData);
			},

			//获取所有代理人， 流程人员信息
			getAllAgent() {

				this.$axios.get('api/user/get_student_info')
					.then(res => {
						if (res.data.code == 200) {
							this.agentOptions = res.data.data
						}
					})
					.catch(err => {
						this.$message({
							type: "err",
							message: err
						});
					});

				this.$axios.get('api/user/process')
					.then(res => {
						if (res.data.code == 200) {

							this.processOptions = res.data.data
						}
					})
					.catch(err => {
						this.$message({
							type: "err",
							message: err
						});
					});

			},

			async search() {
				this.currentPage = 1
				for (var i = 0; i < this.conditionForm.condition.length; i++) {
					let a = this.conditionForm.condition[i].parameter
					if (this.conditionForm.condition[i].parameter === 'subimt_time') {
						this.paramsByOrder.start_time = this.submitTime[0]
						this.paramsByOrder.end_time = this.submitTime[1]
					}
					this.paramsByOrder[a] = this.conditionForm.condition[i].value
				}

				// if (this.$store.state.user.role_id == 2 && this.paramsByOrder.agent_id) {
				// 	this.paramsByOrder.agent_id = this.$store.state.user.id;
				// }
				if (this.$store.state.user.is_teacher == 2) {
					this.paramsByOrder.student_order = true
					this.paramsByOrder.agent_id = this.$store.state.user.id
				} else if(this.$store.state.user.is_teacher == 1) { 
					if (!this.paramsByOrder.agent_id) {
						this.paramsByOrder.all_student_order = true
					} else {
						delete this.paramsByOrder.all_student_order
					}
				} else {
					this.paramsByOrder.agent_id = this.$store.state.user.id
				}


				// 处理分页数据
				delete this.paramsByOrder.page

				// 处理排序状态
				// delete this.paramsByOrder.sort_str
				// delete this.paramsByOrder.sort_order

				this.$refs['orderTb'].clearSort()
				let data = await orderFn.getOrderByasync(this.$axios, this.$store, this.paramsByOrder);
				for (let key in data) {
					this[key] = data[key];
				}
				this.showFilter = false
			},

			// 添加条件筛选
			addFilterCondition(item) {
				let filterItem = {
					value: '',
					label: item.label,
					parameter: item.parameter,
					key: Date.now()
				}

				if (this.conditionForm.condition.length > 0) {
					let conditionlabels = []
					for (let i = 0; i < this.conditionForm.condition.length; i++) {
						conditionlabels.push(this.conditionForm.condition[i].label)
					}
					let Check = conditionlabels.indexOf(item.label)
					Check == -1 ? this.conditionForm.condition.push(filterItem) : this.$message.error('请勿重复添加')
				} else {
					this.conditionForm.condition.push(filterItem)
				}

				this.showFilterCondition = false;
			},

			resetForm(formName) {
				this.$refs[formName].resetFields()
				this.$refs['orderTb'].clearSort()
				this.conditionForm.condition.forEach(v => {
					if (v.value) {
						v.value = null
					}
				});
				this.submitTime = []
				this.paramsByOrder = {
					status: "代理人撰写中,案件内审中,案件修改中,定稿文件发送中,发明人确认定稿中,上报文件上传中,文件格式审核中",
					sort_str: 'pick_up_date',
					sort_order: 'asc',
					agent_id: this.$store.state.user.id
				}
				this.$nextTick(() => {
					this.$refs[formName].clearValidate()
				})
				// this.getData()
				// this.showFilter = false
				// this.showFilterCondition = false
			},

			submitsearch(formName) {
				let that = this
				this.$refs[formName].validate((valid, prop) => {
					// this.$refs[formName].clearValidate();
					let props = []
					for (let k in prop) {
						props.push(prop[k][0].field)
						if (prop[k][0].message = '提交时间不能为空') {
							if (that.submitTime) {
								if (that.submitTime.length > 0) {
									that.$refs[formName].clearValidate([prop[k][0].field])
									// that.search()
									let timeIndex = props.indexOf('提交时间不能为空')
									props.splice(timeIndex, 1)
								}
							}	 else return false
						}

					}
					if (props.length) {
						that.$refs[formName].validateField(props, (valid2) => {
							if (valid2) {
								return false;
							} else {
								that.search()
							}

						})
					} else {
						that.search()
					}
				})
			},
			removeDomain(item) {
				this.showFilter = true
				delete this.paramsByOrder[item.parameter]
				let index = this.conditionForm.condition.indexOf(item)
				if (index !== -1) {
					this.conditionForm.condition.splice(index, 1)
				}

				if (item.label === '提交时间') {
					this.submitTime = []
					delete this.paramsByOrder.start_time
					delete this.paramsByOrder.end_time
				}
				this.search()
			},
			changInput () {
				this.$refs['conditionForm'].clearValidate();
			},
			// 表格排序
			tableSortChange(column) {
				if (column.order === 'descending') {
					this.paramsByOrder.sort_str = column.prop
					this.paramsByOrder.sort_order = 'desc'
				} else if (column.order === 'ascending'){
					this.paramsByOrder.sort_str = column.prop
					this.paramsByOrder.sort_order = 'asc'
				} else {
					delete this.paramsByOrder.sort_str
					delete this.paramsByOrder.sort_order
				}
				// if (this.$store.state.user.role_id == 2 && this.paramsByOrder.agent_id) {
				// 	this.paramsByOrder.agent_id = this.$store.state.user.id;
				// }
				if (this.$store.state.user.is_teacher == 2) {
					this.paramsByOrder.student_order = true
					this.paramsByOrder.agent_id = this.$store.state.user.id
				} else if(this.$store.state.user.is_teacher == 1) { 
					if (!this.paramsByOrder.agent_id) {
						this.paramsByOrder.all_student_order = true
					} else {
						delete this.paramsByOrder.all_student_order
					}
				} else {
					this.paramsByOrder.agent_id = this.$store.state.user.id
				}

				if(column.prop == 'pick_up_date') {
					if(this.paramsByOrder.sort_order == 'asc') {
						this.paramsByOrder.sort_order = 'desc'
					} else {
						this.paramsByOrder.sort_order = 'asc'
					}
				}
				this.loading = true
				this.$axios.get('/api/order', {
					params: this.paramsByOrder
				})
				.then(res => {
					this.loading = false;
					this.tableData = res.data.data;
					this.pageSize = res.data.page.per_page;
					this.tableSize = res.data.page.per_page;
					this.tableEnd = res.data.page.per_page;
					this.total = res.data.page.total;
				})
			},
			gwm() {
            	//水印,非管理员要设置
				if (this.$store.state.user.role_id != 1
					&& this.$route.path != '/admin/register'
					&& this.$route.path != '/admin/personalCenter/dstribution'
					&& this.$route.path != '/admin/personalCenter/myPurse'
					&& this.$route.path != '/admin/activityList/activityConfig'
					&& this.$route.path != '/admin/activityList/sysConfig'
					&& this.$route.path !='/admin/login'
					&& this.$route.path != '/admin/agentImprove'
					&& this.$route.path != '/order/login') {
					let that = this;
					let gwm = require('gwm');
					gwm.creation({
						'txt': that.$store.state.user.name,
						'container': '.el-table', //#gwm
						'fontSize': 40
					})
				}
			},
		},
		watch: {
			tableData: {
				handler: function(val) {
					val.forEach(v => {
						v.imgArr = []
						v.imgArr2 = []
						if (v.thumb_imgs) {
							let arr = v.thumb_imgs.split('&')
							if (v.img) {
								let arr = v.img.split('&')
								for (let i in arr) {
									v.imgArr2.push(this.baseUrl + '/storage/upload/' + arr[i])
								}
							}
							for (let i in arr) {
								v.imgArr.push(this.baseUrl + '/storage/upload/' + arr[i])
							}
						}
					})
				},
				immediate: true
			},
			tableHeader: {
				handler: function(val) {
					let arr = JSON.parse(JSON.stringify(val))
					delete arr.checked
					let select_all = true,
						checked = false;
					for (let i in arr) {
						if (arr[i] == false) {
							select_all = false
						}
						if (arr[i] == true) {
							checked = true
						}
					}
					this.checked99 = checked
					if (select_all) {
						this.tableHeader.checked = true
					} else {
						this.tableHeader.checked = false
					}
					this.table_show = false
					this.$nextTick(() => {
						this.table_show = true
					})
					setTimeout(() => {
						this.$nextTick(() => {
							this.gwm()
						})
					}, 300)
				},
				deep: true
			}
		},
		beforeUpdate() {
			// this.$nextTick(() => {
			// 	this.$refs.orderTb.doLayout();
			// });
		},
		stopLook(path) {

		}
	};
</script>

<style lang="less" scoped>
	.myOreder {
    height: 100%; //撑满表格
    .el-table {
      width: 99.9% !important;
    }
  }
	.file_sh {
		font-size: 25px;
		margin-right: 10px;
	}

	.el-table .warning-row {
		background: oldlace;
	}

	.el-main .ivu-poptip .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 450px;
		// height: 300px;
		overflow-y: scroll;
	}

	.el-main .poptip-condition .ivu-poptip-popper .ivu-poptip-content .ivu-poptip-inner {
		min-width: 180px;
	}

	.demo-dynamic {
		padding-left: 10px;

		.el-form-item {
			margin-bottom: 12px;
		}

		.el-input {
			width: 240px;
		}

		.el-date-editor {
			width: 240px;
		}

		.el-button {
			padding: 9px 15px;
			vertical-align: baseline;
		}

		.el-form-item__error {
			padding-top: 0;
		}

		.btns {
			margin-top: 20px;
		}
	}

	.poptip-condition {
		display: block;
		margin-top: 10px;

		.poptip-condition-item {
			line-height: 25px;
			cursor: pointer;
		}

		.poptip-condition-add {
			font-size: 14px;
		}
	}

	.btns {
		margin-top: 10px;
	}

	.tableLastCol {
		padding-right: 25px ;
		// padding-left: 25px !important;
	}

	.down-execel {
		display: block;
		height: 40px;
		line-height: 40px;
		color: #333333;
		font-size: 14px;
		margin-right: 20px;
		float: right;
	}
	.el-table {
		.img-wrap {
			display: flex;
			justify-content: flex-start;
			> div {
				height: 23px;
			}
			.el-image {
				width: 23px;
				height: 23px;
				margin-right: 5px;
			}
		}
	}
	.el-popover{
		max-height: 300px;
		overflow-y: auto;
		.numberList {
			.number {
				width: 200px;
			}
		}
	}
	.leaveWord {
		color: rgb(16, 133, 16);
		font-size: 18px;
	}

</style>
